﻿using LPLS.Commons.DBModule;
using LPLS.DBEntities;
using LPLS.DBEntities.ConfigModels.DataCollectionConfigModule.DataCollectionType.PLC;
using LPLS.DBInterface.ConfigModels.DataCollectionConfigModule.PLC;
using Microsoft.Identity.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LPLS.DBServices.ConfigModels.DataCollectionConfigModule.PLC
{
    public class PLCVarPropertyConfigService : DBBaseService, IPLCVarPropertyConfigService
    {
        public PLCVarPropertyConfigService(DBContext dbContext) : base(dbContext)
        {
        }

        public int AddData(PLCVarPropertyConfig model)
        {
            return this.Client.Insertable(model).ExecuteCommand();
        }

        public int DeleteData(PLCVarPropertyConfig model)
        {
            return this.Client.Deleteable(model).ExecuteCommand();
        }

        public List<PLCVarPropertyConfig> GetData()
        {
            var data = this.Client.Queryable<PLCVarPropertyConfig>().ToList();


            for (int i = 0; i < data.Count; i++)
            {
                data[i].VarTypeName = data[i].VarType.GetDescription();

            }
            return data;
               
        }

        public override void InitDataBaseName()
        {
            DataBaseName = DatabaseEnum.CollectionConfigDB.ToString();
        }

        public int UpdateData(PLCVarPropertyConfig model)
        {
           return  this.Client.Updateable(model).ExecuteCommand(); 
        }
    }
}
